import storage from 'store'; //这里的这个store，不是vuex中的store,是用的localstorage的第三方库，进行数据的持久化
// import { APP_LANGUAGE } from '@projectCommon/store/modules/i18n/mutation-types';
import { loadLanguageAsync } from '@/locales';

const state = {
  lang: 'zh',
  // _antLocale: {},
};

const mutations = {
  SET_LANGUAGE: (state, lang, antd = {}) => {
    state.lang = lang;
    // state._antLocale = antd;
    // storage.set(APP_LANGUAGE, lang); // 语言变量使用store组件进行存储
  },
};

const actions = {
  setLang({ commit }, lang) {
    return new Promise((resolve, reject) => {
      commit('SET_LANGUAGE', lang);
      loadLanguageAsync(lang)
        .then(() => {
          resolve();
        })
        .catch((e) => {
          reject(e);
        });
    });
  },
};

const getters = {
  lang: (state) => state.lang,
};

export default {
  namespaced: true, //开启命名空间，更好的区分使用stage,防止不同stage模块中的方法重名
  state,
  getters,
  mutations,
  actions,
};
